﻿<localControlsRelations:RelationBase x:Class="ICSharpCode.Data.EDMDesigner.Core.UI.UserControls.Relations.Association"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:localControlsRelations="clr-namespace:ICSharpCode.Data.EDMDesigner.Core.UI.UserControls.Relations"
    xmlns:localControlsMenu="clr-namespace:ICSharpCode.Data.EDMDesigner.Core.UI.UserControls.ContextMenu"
    xmlns:localBindindingConverter="clr-namespace:ICSharpCode.Data.EDMDesigner.Core.UI.Converters"
    PreviewMouseDown="AssociationPreviewMouseDown"
    Focusable="True">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="..\SelectionRectangleResourceDictionary.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <localBindindingConverter:AssociationToMarginConverter x:Key="AssociationToMarginConverter" />
            <localBindindingConverter:AssociationToAlignmentConverter x:Key="AssociationToAlignmentConverter" />
            <localBindindingConverter:AssociationToVisibleConverter x:Key="AssociationToVisibleConverter" />
            <localBindindingConverter:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
            <localBindindingConverter:DesignerAssociationToSelectionLocationConverter x:Key="DesignerAssociationToSelectionLocationConverter" />
        </ResourceDictionary>
    </UserControl.Resources>

    <UserControl.ContextMenu>
        <localControlsMenu:ContextMenu>
            <localControlsMenu:MenuItem x:Name="deleteMenuItem" Header="{x:Static localControlsRelations:Association.DeleteText}" Command="{x:Static localControlsRelations:Association.DeleteCommand}" InputGestureText="Del">
                <localControlsMenu:MenuItem.Icon>
                    <Image Source="../../CSDLType/Resources/Delete.png" Width="16" Height="16" />
                </localControlsMenu:MenuItem.Icon>
            </localControlsMenu:MenuItem>
            <localControlsMenu:MenuSeparator/>
            <localControlsMenu:MenuItem x:Name="propertiesMenuItem" Header="{x:Static localControlsRelations:Association.PropertiesText}" Command="{x:Static localControlsRelations:Association.PropertiesCommand}" InputGestureText="F4" />
            <localControlsMenu:MenuItem x:Name="mappingMenuItem" Header="{x:Static localControlsRelations:Association.MappingText}" Command="{x:Static localControlsRelations:Association.MappingCommand}" InputGestureText="Ctrl+Shift+M" />
        </localControlsMenu:ContextMenu>
    </UserControl.ContextMenu>

    <UserControl.InputBindings>
        <KeyBinding Key="Delete" Command="{x:Static localControlsRelations:Association.DeleteCommand}" />
        <KeyBinding Key="F4" Command="{x:Static localControlsRelations:Association.PropertiesCommand}" />
        <KeyBinding Key="M" Modifiers="CTRL+Shift" Command="{x:Static localControlsRelations:Association.MappingCommand}" />
    </UserControl.InputBindings>

    <Grid>
        <Line x:Name="line" Stroke="Black" TargetUpdated="line_TargetUpdated"
              X1="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=X1, NotifyOnTargetUpdated=True}"
              X2="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=X2, NotifyOnTargetUpdated=True}"
              Y1="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=Y1, NotifyOnTargetUpdated=True}"
              Y2="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=Y2, NotifyOnTargetUpdated=True}"
              Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Converter={StaticResource AssociationToVisibleConverter}, ConverterParameter='1'}" MouseLeftButtonDown="Line_MouseLeftButtonDown"/>
        <Line x:Name="line2" Stroke="Black" TargetUpdated="line_TargetUpdated"
              X1="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=X2, NotifyOnTargetUpdated=True}"
              X2="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=X3, NotifyOnTargetUpdated=True}"
              Y1="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=Y2, NotifyOnTargetUpdated=True}"
              Y2="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=Y3, NotifyOnTargetUpdated=True}"
              Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Converter={StaticResource AssociationToVisibleConverter}}" MouseLeftButtonDown="Line_MouseLeftButtonDown"/>
        <Line x:Name="line3" Stroke="Black" TargetUpdated="line_TargetUpdated"
              X1="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=X3, NotifyOnTargetUpdated=True}"
              X2="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=X4, NotifyOnTargetUpdated=True}"
              Y1="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=Y3, NotifyOnTargetUpdated=True}"
              Y2="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=Y4, NotifyOnTargetUpdated=True}"
              Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Converter={StaticResource AssociationToVisibleConverter}}" MouseLeftButtonDown="Line_MouseLeftButtonDown"/>
        <TextBlock x:Name="tb1" Text="{Binding  RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=FromCardinality}" HorizontalAlignment="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Converter={StaticResource AssociationToAlignmentConverter}, ConverterParameter='X1'}" VerticalAlignment="Top" Margin ="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Converter={StaticResource AssociationToMarginConverter}, ConverterParameter='From'}" Foreground="Blue" Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=FromTypeDesigner.IsExpanded, Converter={StaticResource BoolToVisibilityConverter}}" />
        <TextBlock x:Name="tb2" Text="{Binding  RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=ToCardinality}" HorizontalAlignment="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Converter={StaticResource AssociationToAlignmentConverter}, ConverterParameter='X2'}" VerticalAlignment="Top" Margin ="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Converter={StaticResource AssociationToMarginConverter}, ConverterParameter='To'}" Foreground="Blue" Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=ToTypeDesigner.IsExpanded, Converter={StaticResource BoolToVisibilityConverter}}" />
        <Rectangle x:Name="selectionRectangle1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Converter={StaticResource DesignerAssociationToSelectionLocationConverter}, ConverterParameter=1}" Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=IsSelected, Converter={StaticResource BoolToVisibilityConverter}}" />
        <Rectangle x:Name="selectionRectangle2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Converter={StaticResource DesignerAssociationToSelectionLocationConverter}, ConverterParameter=2}" Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type localControlsRelations:Association}}, Path=IsSelected, Converter={StaticResource BoolToVisibilityConverter}}" />
    </Grid>
</localControlsRelations:RelationBase>
